LOCAL_DIR := $(GET_LOCAL_DIR)

MODULE := $(LOCAL_DIR)

# ROMBASE, MEMBASE, and MEMSIZE are required for the linker script

ROMBASE := 0x60000000
MEMBASE := 0x20200000

# default memsize, specific IMXRT_CHIP may override this
# and target/project may have already overridden
MEMSIZE := 0x40000

ARCH := arm
ARM_CPU := cortex-m7

# TODO: integrate better with platform
ifeq ($(IMXRT_CHIP),imxrt1021)
GLOBAL_DEFINES += CPU_MIMXRT1021CAF4A
FOUND_CHIP := true
endif

ifeq ($(FOUND_CHIP),)
$(error unknown IMXRT10XX chip $(IMXRT_CHIP))
endif

GLOBAL_DEFINES += \
	XIP_EXTERNAL_FLASH=1 \
	XIP_BOOT_HEADER_ENABLE=1 \
	FSL_SDK_ENABLE_DRIVER_CACHE_CONTROL=1 \
	MEMSIZE=$(MEMSIZE)

GLOBAL_INCLUDES += \
	$(LOCAL_DIR)/include/dev

ifeq ($(MEMSIZE),)
$(error need to define MEMSIZE)
endif

MODULE_SRCS += \
	$(LOCAL_DIR)/init.c \
	$(LOCAL_DIR)/debug.c \
	$(LOCAL_DIR)/uart.c \
	$(LOCAL_DIR)/vectab.c \
	$(LOCAL_DIR)/timer.c \
	$(LOCAL_DIR)/swdt.c \
	$(LOCAL_DIR)/mdio.c \
	$(LOCAL_DIR)/iomuxc.c \
	$(LOCAL_DIR)/gpio.c


# use a two segment memory layout, where all of the read-only sections 
# of the binary reside in rom, and the read/write are in memory. The 
# ROMBASE, MEMBASE, and MEMSIZE make variables are required to be set 
# for the linker script to be generated properly.
#
LINKER_SCRIPT += \
	$(BUILDDIR)/system-imxrt-twosegment.ld

MODULE_DEPS += \
	arch/arm/arm-m/systick \
	platform/imxrt1021/MIMXRT1021 \
	lib/cbuf


include make/module.mk
